package com.longxi.tianjintianbao.ui.adapter.multitype;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.SelectTaskListListener;
import com.longxi.tianjintianbao.model.task.Task;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class TaskListViewBinder extends ItemViewBinder<Task, TaskListViewBinder.ViewHolder> {

    SelectTaskListListener listener;

    public TaskListViewBinder(SelectTaskListListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_task_list, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Task task) {
        holder.mTvDate.setText(task.getBilldate());
        holder.mTvStatus.setText(task.getState());
        holder.mTvName.setText(task.getPerson());
//        holder.mTvName.setText(task.get() + "项");
//        holder.mTvAddress.setText(quality.getScore() + "分");
        holder.mTvTaskContent.setText(task.getContent());

        holder.mLlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onSuccess(task);
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mLlBtn;
        TextView mTvDate;
        TextView mTvStatus;
        TextView mTvName;
        TextView mTvAddress;
        TextView mTvTaskContent;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvDate = itemView.findViewById(R.id.tvDate);
            mTvStatus = itemView.findViewById(R.id.tvStatus);
            mTvName = itemView.findViewById(R.id.tvName);
            mTvAddress = itemView.findViewById(R.id.tvAddress);
            mTvTaskContent = itemView.findViewById(R.id.tvTaskContent);
        }
    }
}
